<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>供应商用户关系角色管理</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var formSetting = {
        title: "查询用户关系角色信息",
        module: 'query',
        columns: [{
            name: "NAME",
            label: "角色名称"
        }/*, {
         name : "SYS_ID",
         label : "业务系统用户名"
         } , {
         name : "identifier",
         label : "标识符"
         }, {
         name : "use_state",
         label : "使用状态",
         type : "dropdown",
         data : [ [ "启用", "0" ], [ "未启用", "1" ] ]
         } */],
        buttons: {
            custom: [
                {
                    id: "addbtn",
                    value: "新增",
                    click: function () {
                        //$('#center', window.parent.document).attr("src","supCustomerRole-manage");
                        window.location.href = "supCustomerRole-manage";
                    }
                },
                {
                    id: "updateBtn2",
                    value: "设为默认",
                    click: function () {
                        var id = $("#supCustomerRolesDataGrid").jqGrid("getGridParam",
                                                                       "selrow");
                        if (id) {
                            //if (confirm("确定要设置该项为默认角色?")) {
                            jw.confirm("确定要设置该项为默认角色?", function () {
                                           var ret = $("#supCustomerRolesDataGrid").jqGrid('getRowData', id);
                                           var data = "id=" + ret.iD;
                                           $.ajax({
                                                      url: "supCustomerRole-setDefault",
                                                      dataType: "json",
                                                      data: data,
                                                      success: function (data) {
                                                          jw.alert($.parseJSON(data.msg).msg);
                                                          if ($.parseJSON(data.msg).state == "1") {
                                                              $("#supCustomerRolesDataGrid").jqGrid(
                                                                      "setGridParam",
                                                                      {
                                                                          search: true
                                                                          // 将jqGrid的search选项设为true
                                                                      }).trigger("reloadGrid", [{
                                                                  page: 1
                                                              }]);
                                                          }
                                                      }
                                                  });
                                       },
                                       function () {
                                           return;
                                       });
                            //}
                        } else {
                            jw.alert("请点击需要修改的数据!");
                        }
                    }
                },
                {
                    id: "updateBtn",
                    value: "修改",
                    click: function () {
                        var id = $("#supCustomerRolesDataGrid").jqGrid("getGridParam",
                                                                       "selrow");
                        if (id) {
                            var ret = $("#supCustomerRolesDataGrid").jqGrid('getRowData', id);
                            //$('#center', window.parent.document).attr("src","supCustomerRole-manage?supCustomerRole.ID="+ret.ID);
                            window.location.href =
                                    "supCustomerRole-manage?id=" + ret.iD;
                        } else {
                            jw.alert("请点击需要修改的数据!");
                        }
                    }
                },
                {
                    id: "delbtn",
                    value: "删除",
                    click: function () {
                        var selectedIds = $("#supCustomerRolesDataGrid").jqGrid(
                                "getGridParam", "selarrrow");
                        if (selectedIds.length > 0) {
                            //if (confirm("确定要删除选择的项?")) {
                            jw.confirm("确定要删除选择的项?", function () {
                                           var data = "id=";
                                           for (i in selectedIds) {
                                               var ret = $("#supCustomerRolesDataGrid").jqGrid('getRowData',
                                                                                               selectedIds[i]);
                                               data += ret.iD + ",";
                                           }
                                           data = data.substring(0, data.length - 1);
                                           $.ajax({
                                                      url: "supCustomerRole-del",
                                                      dataType: "json",
                                                      data: data,
                                                      success: function (data) {
                                                          jw.alert(data.msg);
                                                          $("#supCustomerRolesDataGrid").jqGrid("setGridParam",
                                                                                                {
                                                                                                    search: true
                                                                                                    // 将jqGrid的search选项设为true
                                                                                                }).trigger(
                                                                  "reloadGrid", [{
                                                                      page: 1
                                                                  }]);
                                                      }
                                                  });
                                       },
                                       function () {
                                           return;
                                       });
                            //}
                        } else {
                            jw.alert("请点击需要删除的数据!");
                        }
                    }
                }]
        },
        grid: {
            id: "supCustomerRolesDataGrid",
            title: "查询结果",
            url: "supCustomerRole-findList",
            multiselect: true,
            /* postData : {
             "pid" : pid
             }, */
            colModel: [{
                index: "iD",
                name: "iD",
                hidden: true
            }, {
                index: "nAME",
                name: "nAME",
                label: "用户角色名称"
            }, {
                index: "iS_DEFAULT",
                name: "iS_DEFAULT",
                label: "默认角色"
            }/*,{
             index : "SYS_ID",
             name : "SYS_ID",
             label : "业务系统用户名"
             } , {
             index : "en",
             name : "en",
             label : "英文名"
             }, {
             index : "identifier",
             name : "identifier",
             label : "标识符"
             }, {
             index : "use_state",
             name : "use_state",
             label : "使用状态",
             formatter : function(cellvalue, options, rowObject) {
             if (cellvalue == "0") {
             return "启用";
             } else {
             return "禁用";
             }
             }
             }, {
             index : "updateUser",
             name : "updateUser",
             label : "修改人"
             }, {
             index : "updateDate",
             name : "updateDate",
             label : "修改时间"
             }  */],
            jsonReader: {
//                root: "supCustomerRoles"
            }
        }
    };
    $(document).ready(function () {
        $("#supCustomerRolesDataTable").mrdForm(formSetting);
    });
</script>
<body>
<div id="supCustomerRolesDataTable"></div>
</body>
</html>
